ValueFolderTemp='/sps/isc/rneveu/EtudeIRM/Nature/ResultsJournal/';
VecValueTime=[0 2 1 5 10 3 4];
VecValueFilter=[0 1];
VecResultsJournal=[];
for n1=1:33
    load([ValueFolderTemp 'FileAnalysisCharacteristicsEditorsJournal' num2str(n1) '.mat']);
    VecResultsJournal=[VecResultsJournal;VecResultsJournalEditor];
end
VecResults=[];
for n5=1:size(VecValueTime,2)
    for n6=1:size(VecValueFilter,2)
        ValueTime=VecValueTime(1,n5);
        ValueFilter=VecValueFilter(1,n6);
        VecResults4=[];
        VecResults3=[];
        VecResults5=[];
        VecResultsCorrelation5=[];
        VecResults52=[];
        VecResults7=[];
        VecResultsJournalTemp=[];
        VecResultsJournalTemp2=[];
        VecValueFigure=[];
        VecValueFigure2=[];
        for n1=1:33
            if ValueTime>=1
                if ValueFilter==0
                    ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
                else
                    ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                end
            else
                if ValueFilter==0
                    ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
                else
                    ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                end
            end
            ValueFile2=['JCR' num2str(n1) '.mat'];
            ValueFileTemp=dir([ValueFolderTemp ValueFile]);
            ValueFileTemp2=dir([ValueFolderTemp ValueFile2]);
            if size(ValueFileTemp,1)==1&&size(ValueFileTemp2,1)==1
                load([ValueFolderTemp ValueFile]);
                load([ValueFolderTemp ValueFile2]);
                n2=1;
                TestTemp=0;
                while n2<=size(VecResultsArticle2,1)&&TestTemp==0
                    if VecResultsArticle2(n2,4)>0
                        TestTemp=1;
                    end
                    n2=n2+1;
                end
                VecValueTemp=VecResultsArticle2(n2-1:end,:);
                VecValue2Temp=VecResultsArticle1(n2-1:end,:);
                VecResults2=VecValueTemp;
                if size(find(VecValueTemp(:,1)>0),1)>0
                    VecResults4=[VecResults4 VecResultsArticle2(:,4)];
                end
                VecValueTemp4=size(VecValueJCR,1):-1:1;
                VecValueJCR=VecValueJCR(VecValueTemp4,:);
                if size(VecValueJCR,1)>=size(VecValueTemp,1)
                    VecValueJCR=VecValueJCR(size(VecValueJCR,1)-size(VecValueTemp,1)+2:size(VecValueJCR,1),:);
                end
                if size(VecValueTemp,1)>3
                    VecValueTemp=VecValueTemp(size(VecValueTemp,1)-size(VecValueJCR,1):size(VecValueTemp,1),:);
                    VecValue2Temp=VecValue2Temp(size(VecValue2Temp,1)-size(VecValueJCR,1):size(VecValue2Temp,1),:);
                    VecValueTemp2=1:size(VecValueTemp,1);
                    VecValueTemp2=VecValueTemp2';
                    VecValueTemp2=VecValueTemp2-1;
                    VecValueTemp4=1:size(VecValueJCR,1);
                    VecValueTemp4=VecValueTemp4';
                    VecValueTemp4=VecValueTemp4-1;
%                     VecValueTemp5=[VecValueTemp(:,3)./VecValueTemp(:,4)*100 VecValueTemp(:,1)./VecValueTemp(:,3)*100 VecValueTemp(:,2)./VecValueTemp(:,3)*100];
%                     VecValueTemp5=[VecValueTemp(:,3) VecValueTemp(:,4) VecValueTemp(:,2)];
                    VecValueTemp5=[VecValueTemp(:,3) VecValueTemp(:,1) VecValueTemp(:,2)];
%                     VecValueTemp5=[(VecValueTemp(1:end-1,3)+VecValueTemp(2:end,3))./(VecValueTemp(1:end-1,4)+VecValueTemp(2:end,4))*100 (VecValueTemp(1:end-1,1)+VecValueTemp(2:end,1))./(VecValueTemp(1:end-1,3)+VecValueTemp(2:end,3))*100 (VecValueTemp(1:end-1,2)+VecValueTemp(2:end,2))./(VecValueTemp(1:end-1,3)+VecValueTemp(2:end,3))*100];
%                     VecValueTemp2=VecValueTemp2(1:end-1,:);
                    VecValueTemp51=[VecValue2Temp(:,3)./VecValue2Temp(:,4)*100 VecValue2Temp(:,1)./VecValue2Temp(:,3)*100 VecValue2Temp(:,2)./VecValue2Temp(:,3)*100];
                    ValueTemp5=find(VecValueTemp(:,4)==0);
                    VecValueTemp5(ValueTemp5,:)=zeros(size(ValueTemp5,1),3);
                    ValueTemp5=find(VecValueTemp(:,3)==0);
                    VecValueTemp5(ValueTemp5,:)=zeros(size(ValueTemp5,1),3);
                    ValueTemp5=find(VecValue2Temp(:,4)==0);
                    VecValueTemp51(ValueTemp5,:)=zeros(size(ValueTemp5,1),3);
                    ValueTemp5=find(VecValue2Temp(:,3)==0);
                    VecValueTemp51(ValueTemp5,:)=zeros(size(ValueTemp5,1),3);
                    ValueResults2=regress(VecValueTemp5(:,2),[ones(size(VecValueTemp2,1),1) VecValueTemp2]);
                    ValueResults3=regress(VecValueTemp5(:,3),[ones(size(VecValueTemp2,1),1) VecValueTemp2]);
                    ValueResults4=regress(VecValueJCR(:,4),[ones(size(VecValueTemp4,1),1) VecValueTemp4]);
                    VecValueJCRTemp=VecValueJCR;
                    VecValueJCR(:,4)=VecValueJCR(:,4)-ValueResults4(1,1)-ValueResults4(2,1)*VecValueTemp4;
                    ValueResults4=regress(VecValueJCR(:,5),[ones(size(VecValueTemp4,1),1) VecValueTemp4]);
                    VecValueJCR(:,5)=VecValueJCR(:,5)-ValueResults4(1,1)-ValueResults4(2,1)*VecValueTemp4;
                    ValueResults4=regress(VecValueJCR(:,6),[ones(size(VecValueTemp4,1),1) VecValueTemp4]);
                    VecValueJCR(:,6)=VecValueJCR(:,6)-ValueResults4(1,1)-ValueResults4(2,1)*VecValueTemp4;
                    ValueResults4=regress(VecValueJCR(:,3),[ones(size(VecValueTemp4,1),1) VecValueTemp4]);
                    VecValueJCR(:,3)=VecValueJCR(:,3)-ValueResults4(1,1)-ValueResults4(2,1)*VecValueTemp4;
                    VecResultsJournalTemp=[VecResultsJournalTemp;ValueResults2(2,1) ValueResults3(2,1) ValueResults4(2,1)];
%                     VecValueTemp5=VecValueTemp5(2:end,:);
%                     VecValueTemp2=VecValueTemp2(2:end,:);
                    VecValueTemp5=VecValueTemp5(1:end-1,:);
                    VecValueTemp2=VecValueTemp2(1:end-1,:);
                    VecValueJCRTemp2=VecValueJCR;
                    VecValueJCR=VecValueJCRTemp;
                    VecValueTime2=1:size(VecValueJCR,1)-2;
%                     VecValueTime2=1:size(VecValueJCR,1)-1;
%                     VecValueTime2=1:size(VecValueJCR,1)-2;
                    VecValueTime2=sort(-VecValueTime2);
%                     VecValueFigure=[VecValueFigure;VecValueTemp5 VecValueJCR(:,3:6) n1*ones(size(VecValueTemp5,1),1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1),1)];
%                     VecValueFigure=[VecValueFigure;VecValueTemp5 n1*ones(size(VecValueTemp5,1),1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1),1)];
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(2:end,:)-VecValueTemp5(1:end-1,:) VecValueJCR(2:end,3:6)-VecValueJCR(1:end-1,3:6) n1*ones(size(VecValueTemp5,1)-1,1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-1,1)];
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(3:end,:)-VecValueTemp5(1:end-2,:) VecValueJCR(2:end-1,3:6)-VecValueJCR(1:end-2,3:6) n1*ones(size(VecValueTemp5,1)-2,1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-2,1)];
%                     VecValueFigure=[VecValueFigure;(VecValueTemp5(3:end,:)-VecValueTemp5(1:end-2,:))./(VecValueTemp5(3:end,1)-VecValueTemp5(1:end-2,1))*100 VecValueJCR(2:end-1,3:6)-VecValueJCR(1:end-2,3:6) n1*ones(size(VecValueTemp5,1)-2,1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-2,1)];
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(3:end,:)-VecValueTemp5(2:end-1,:) VecValueJCR(2:end-1,3:6)-VecValueJCR(1:end-2,3:6) n1*ones(size(VecValueTemp5,1)-2,1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-2,1)];
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(2:end,:)-VecValueTemp5(1:end-1,:) VecValueJCR(2:end,3:6)-VecValueJCR(1:end-1,3:6) n1*ones(size(VecValueTemp5,1)-1,1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-1,1)];
                    VecValueFigure=[VecValueFigure;VecValueTemp5(1:end-2,:) VecValueJCR(3:end,3:6) n1*ones(size(VecValueTemp5,1)-2,1) VecValueTime2' repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-2,1)]; % N articles and absolute value of IF for year n-2 and year n respectively
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(2:end,:) VecValueJCR(1:end-1,3:6) n1*ones(size(VecValueTemp5,1)-1,1) VecValueTime2' repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-1,1)]; % N articles and absolute value of IF for year n+1 and year n respectively
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(3:end,:) VecValueJCR(1:end-2,3:6) n1*ones(size(VecValueTemp5,1)-2,1) VecValueTime2' repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-2,1)]; % N articles and absolute value of IF for year n+2 and year n respectively
%                     VecValueFigure=[VecValueFigure;VecValueTemp5(2:end,:)-VecValueTemp5(1:end-1,:) (VecValueJCR(2:end,3:6)-VecValueJCR(1:end-1,3:6))*2./(VecValueJCR(2:end,3:6)+VecValueJCR(1:end-1,3:6))*100 n1*ones(size(VecValueTemp5,1)-1,1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1)-1,1)];
                    VecValueTemp5(:,2)=VecValueTemp5(:,2)-ValueResults2(1,1)-ValueResults2(2,1)*VecValueTemp2;
                    VecValueTemp5(:,3)=VecValueTemp5(:,3)-ValueResults3(1,1)-ValueResults3(2,1)*VecValueTemp2;
                    VecValueJCR=VecValueJCRTemp2;
                    VecValueFigure2=[VecValueFigure2;VecValueTemp5 VecValueJCR(:,3:6) n1*ones(size(VecValueTemp5,1),1) repmat(VecResultsJournal(n1,:),size(VecValueTemp5,1),1)];
                    ValueResults2=regress(VecValueTemp5(:,2),[ones(size(VecValueTemp2,1),1) VecValueJCR(:,3)]);
                    ValueResults3=regress(VecValueTemp5(:,3),[ones(size(VecValueTemp2,1),1) VecValueJCR(:,3)]);
                    VecResultsJournalTemp2=[VecResultsJournalTemp2;ValueResults2(2,1) ValueResults3(2,1)];
                end
            end
        end
        [ValueResults1,ValueResults2]=corr(VecResultsJournalTemp(:,1),VecResultsJournalTemp(:,3),'type','pearson');
        [ValueResults1Temp,ValueResults2Temp]=corr(VecResultsJournalTemp(:,1),VecResultsJournalTemp(:,3),'type','spearman');
        [ValueResults3,ValueResults4]=corr(VecResultsJournalTemp(:,2),VecResultsJournalTemp(:,3),'type','pearson');
        [ValueResults3Temp,ValueResults4Temp]=corr(VecResultsJournalTemp(:,2),VecResultsJournalTemp(:,3),'type','spearman');
        [ValueResults5,ValueResults6]=ttest(VecResultsJournalTemp2(:,1));
        [ValueResults5Temp,ValueResults6Temp]=signrank(VecResultsJournalTemp2(:,1));
        [ValueResults7,ValueResults8]=ttest(VecResultsJournalTemp2(:,2));
        [ValueResults7Temp,ValueResults8Temp]=signrank(VecResultsJournalTemp2(:,2));
        VecResults=[VecResults;ValueResults1 ValueResults2 ValueResults1Temp ValueResults2Temp NaN ValueResults3 ValueResults4 ValueResults3Temp ValueResults4Temp NaN VecValueTime(1,n5) VecValueFilter(1,n6) NaN mean(VecResultsJournalTemp2(:,1)) sqrt(var(VecResultsJournalTemp2(:,1))) ValueResults6 ValueResults5Temp NaN mean(VecResultsJournalTemp2(:,2)) sqrt(var(VecResultsJournalTemp2(:,2))) ValueResults8 ValueResults7Temp];
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCR.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRn.mat'],'VecValueFigure');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRDifference.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRnDifference.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRnDifference2.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRDifference2.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRDifference22.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRnDifference3.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRnDifference4.mat'],'VecValueFigure','VecValueFigure2');
        save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRn.mat'],'VecValueFigure'); % N articles and absolute value of IF for year n-2 and year n respectively
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRn2.mat'],'VecValueFigure'); % N articles and absolute value of IF for year n+1 and year n respectively
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRn3.mat'],'VecValueFigure'); % N articles and absolute value of IF for year n+2 and year n respectively
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRnDifferenceRatio.mat'],'VecValueFigure','VecValueFigure2');
%         save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'JCRnArticle.mat'],'VecValueFigure','VecValueFigure2');
    end
end
        